import HeroContact, {colliderGroup} from "./HeroContact";
import GameData_red_blue_man from "./GameData_red_blue_man";
import PlaySpecialMusic from "./PlaySpecialMusic";
import {musicName} from "../PublicScript/Music";

const {ccclass, property} = cc._decorator;

@ccclass
export default class Wind_box extends cc.Component {

    start () {
        let nodeWidthMax = this.node.parent.x + this.node.parent.width/2;
        let nodeWidthMin = this.node.parent.x - this.node.parent.width/2;
        let nodeHeightMax = this.node.parent.y + this.node.parent.height/2;
        let nodeHeightMin = this.node.parent.y - this.node.parent.height/2;

        console.log(nodeWidthMax, nodeWidthMin, nodeHeightMax, nodeHeightMin);

        GameData_red_blue_man.windStateList.push(false);
        let tag = GameData_red_blue_man.windStateList.length - 1;
        let special = this.node.addComponent(PlaySpecialMusic);
        special.setValue({name: musicName.hair_drier_sound, widthMax: nodeWidthMax, widthMin: nodeWidthMin, HeightMax: nodeHeightMax, HeightMin: nodeHeightMin, tag: tag});
        // cc.loader.loadRes("Sound/" + musicName.hair_drier_sound, cc.AudioClip, (err,res)=>{
        //     cc.audioEngine.playEffect(res,true);
        // });
    }

    onPreSolve(contact, self, other) {
        other.node.getComponent(HeroContact).jumpAnim();
        contact.disabled = true;
        if(self.tag == 1){
            other.body.linearVelocity = cc.v2(other.body.linearVelocity.x, 350)
        }else{
            other.body.linearVelocity = cc.v2(other.body.linearVelocity.x, other.body.linearVelocity.y += 15)
        }

    }

    // update (dt) {}
}
